<template>
	<view>
    <!-- // 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
		  <swiper-item v-for="(v,i) in swiperList" :key="v.goods_id">
		    <navigator class="swiper-item" :url = "'/subpkg/goods_detail/goods_detail?good_id='+v.goods_id">
          <image :src="v.image_src" mode=""></image>
        </navigator>
		  </swiper-item>
		</swiper>
    <!-- 分类导航区 -->
    <view class="nav-list">
      <view class="nav-item" v-for="(v,i) in navList" :key="i" @click = "navClickHandler(v)">
        <image :src="v.image_src" mode="" class="nav-image"></image>
      </view>
    </view>
    <!-- 楼层区域 -->
    <!-- 楼层的容器 -->
    <view class="floor-list" >
      <!-- 每个楼层的item项 -->
      <view class="floor-item" v-for="(item , i) in floorList" :key="i">
        <!-- 楼层标题 -->
         <image :src="item.floor_title.image_src" class="floor-title"></image>
         <!-- 装图片盒子 -->
         <view class="floor-img-box">
          <!-- 装图片左侧盒子 -->
           <navigator class="left-img-box" :url="item.product_list[0].url">
             <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
           </navigator>
           <!-- 装图片右侧盒子 -->
           <view class="right-img-box">
             <navigator class="right-img-item" v-for="(v,i2) in item.product_list" :key="i2" v-if="i2 !== 0" :url="v.url">
               <image :src="v.image_src" :style="{width:v.image_width + 'rpx'}" mode="widthFix"></image>
             </navigator>
           </view>
         </view>
      </view>
 
    </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 轮播图的数据列表
        swiperList:[],
        // 获取nav导航列表
        navList:[],
        // 楼层列表
        floorList:[]
			};
		},
    // 2 小程序页面刚加载的时候 调用获取轮播图 
    onLoad(){
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    onShow(){
    },
    methods:{
      // 3.获取轮播图数据的方法
     async getSwiperList(){
        // 发起请求
        const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
        // 判断请求是否成功
        console.log(res)
        if(res.meta.status !== 200){
          return  uni.showToast({
            title:"请求失败",
            duration:1500,
            icon:"none"
          })
        }
        this.swiperList = res.message
      },
      async getNavList(){
        const { data: res } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navList = res.message
      },  
      // 获取楼层数据
      async getFloorList(){
        const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
        if(res.meta.status !== 200){
          return uni.$showMsg()
        }
        res.message.forEach(v => {
         v.product_list.forEach(v2 => {
             v2.url = '/subpkg/goods_list/goods_list?' + v2.navigator_url.split('?')[1]
          })
        })
        console.log(res.message)
        this.floorList = res.message
      },
      navClickHandler(v){
        console.log(v)
        if(v.name === "分类"){
          uni.switchTab({
            url:'/pages/cate/cate'
          })
        }
      }
    },
    
	}
</script>

<style lang="scss">
  swiper{
    height: 300rpx;
    .swiper-item image {
      width:100%;
      herght:100%
    }
  }
  .nav-list{
    display: flex;
    justify-content: space-around;
    margin: 15px 0;
    .nav-image{
      width:128rpx;
      height: 140rpx;
    }
  }
  .floor-title {
    height: 60rpx;
    width: 100%;
    // display: flex;
  }
  
    
  .floor-img-box{
    display: flex;
    justify-content: space-between;
    padding-left: 10rpx;
    .right-img-box{
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
    }
  }
  

</style>
